<template>
  <div class="goodsDetailPage">
    <van-nav-bar
      title="商品介绍"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="goodsDetailPageInner">
      <div class="shopCover">
        <img
          v-if="goodsDetail.hasOwnProperty('picFile')"
          :src="goodsDetail.picFile.url"
          alt="">
      </div>
      <div class="shopInfo">
        <div class="shopName">
          <span>{{goodsDetail.name}}</span>
        </div>
        <div
          v-if="goodsDetail.tagsList.length"
          class="shopTag" >
          <van-tag
            plain
            v-for="item in goodsDetail.tagsList"
            type="primary">
            {{ item }}
          </van-tag>
        </div>
        <p class="shopDetail">
          {{goodsDetail.remark}}
        </p>
<!--        <MerchantCard-->
<!--          v-if="merchantDetail.hasOwnProperty('id')"-->
<!--          :merchantData="merchantDetail"-->
<!--        />-->
        <div class="shopGoodsList">
          <div>
            <span>餐厅其他美食</span>
          </div>
          <ul>
            <li
              v-for="item in goodsOtherList"
              :key="item.id"
            >
              <van-image
                width="100%"
                height="100"
                radius="12"
                fit="cover"
                :src="item.picFile.url"
              />
              <div>{{ item.name }}</div>
              <div>
                <span>{{ item.price }}</span>
              </div>
            </li>
          </ul>
        </div>

      </div>
    </div>
  </div>
</template>
<script setup>
import MerchantCard from './merchantCard.vue'
import { goodsDetailById } from "@/api/homePage.js";
import { useRoute } from 'vue-router'
const route = useRoute();
const { goodsId } = route.query;

//获取详情
onMounted(() => { getGoodsDetail() })
const goodsDetail = ref({ tagsList: [] });
const goodsOtherList = ref([]);
const merchantDetail = ref({});
const getGoodsDetail = () => {
  goodsDetailById({ id: goodsId }).then(res => {
    const { goods, goodsListNot, merchant } = res.data;
    goodsDetail.value = {
      ...goods,
      tagsList: goods.tags.split(','),
    };
    goodsOtherList.value = goodsListNot;
    merchantDetail.value = merchant;
  })
}

//返回
const onClickLeft = () => history.back();

</script>
<style lang="less" scoped>
div.goodsDetailPage {
  width: 100%;
  height: 100%;
  position: relative;
  div.goodsDetailPageInner {
    height: calc(100% - 46px);
    overflow: auto;
    position: relative;
    >.shopCover {
      height: 249px;
      overflow: hidden;
      img {
        width: 100%;
      }
    }
    >.shopInfo {
      width: 100%;
      height: calc(100% - 229px);
      border-radius: 24px 24px 0 0;
      background: #ffffff;
      position: absolute;
      top: 229px;
      left: 0;
      padding: 12px;
      box-sizing: border-box;
      >.shopName {
        font-size: 24px;
        font-weight: bold;
      }
      >.shopTag {
        margin-bottom: 6px;
        .van-tag {
          margin-right: 12px;
        }
      }
      >.shopDetail {
        font-size: 15px;
        color: rgba(25, 25, 25, 1);
      }
      >.shopGoodsList {
        width: 100%;
        padding: 12px;
        box-sizing: border-box;
        border-radius: 16px;
        box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.1);
        >div:first-child {
          span {
            color: #000000;
            font-size: 18px;
            font-weight: bold;
          }
        }
        ul {
          display: flex;
          justify-content: start;
          align-items: center;
          li {
            width: calc((100% - 24px) / 3);
            &:not(:last-child) {
              margin-right: 12px;
            }
            >div:nth-child(2) {
              height: 20px;
              line-height: 20px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              font-size: 12px;
              font-weight: bold;
            }
            >div:nth-child(3) {
              height: 20px;
              line-height: 20px;
              span {
                font-size: 12px;
                font-weight: bold;
                color: rgba(251, 93, 59, 1);
              }
            }
          }
        }
      }
    }
  }
}
</style>
